home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / fldpak / fpdemo1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-11-29  |  9.6 KB  |  234 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Invoice Browser (FieldPack demo program 1)"
  6.    ClientHeight    =   2505
  7.    ClientLeft      =   2220
  8.    ClientTop       =   1995
  9.    ClientWidth     =   5655
  10.    Height          =   3195
  11.    Left            =   2160
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   2505
  15.    ScaleWidth      =   5655
  16.    Top             =   1365
  17.    Width           =   5775
  18.    Begin ListBox lstInvoices 
  19.       FontBold        =   -1  'True
  20.       FontItalic      =   0   'False
  21.       FontName        =   "Courier"
  22.       FontSize        =   9.75
  23.       FontStrikethru  =   0   'False
  24.       FontUnderline   =   0   'False
  25.       Height          =   1005
  26.       Left            =   810
  27.       Sorted          =   -1  'True
  28.       TabIndex        =   2
  29.       Top             =   1080
  30.       Width           =   4035
  31.    End
  32.    Begin TextBox txt_hidden_NumberOfInvoices 
  33.       BackColor       =   &H00808080&
  34.       DataField       =   "NumberOfInvoices"
  35.       DataSource      =   "Data1"
  36.       Height          =   285
  37.       Left            =   4440
  38.       TabIndex        =   0
  39.       Top             =   0
  40.       Visible         =   0   'False
  41.       Width           =   495
  42.    End
  43.    Begin Data Data1 
  44.       BackColor       =   &H0000FF00&
  45.       Caption         =   "Customer Name"
  46.       Connect         =   ""
  47.       DatabaseName    =   "c:\FPDEMO1.MDB"
  48.       Exclusive       =   0   'False
  49.       ForeColor       =   &H00000000&
  50.       Height          =   270
  51.       Left            =   1440
  52.       Options         =   0
  53.       ReadOnly        =   0   'False
  54.       RecordSource    =   "InvoicesByCustomer"
  55.       Top             =   240
  56.       Width           =   2565
  57.    End
  58.    Begin Label lblCountDisplay 
  59.       BackColor       =   &H00C0C0C0&
  60.       Caption         =   "3"
  61.       FontBold        =   -1  'True
  62.       FontItalic      =   0   'False
  63.       FontName        =   "MS Sans Serif"
  64.       FontSize        =   12
  65.       FontStrikethru  =   0   'False
  66.       FontUnderline   =   0   'False
  67.       ForeColor       =   &H000000FF&
  68.       Height          =   255
  69.       Left            =   2850
  70.       TabIndex        =   6
  71.       Top             =   2130
  72.       Width           =   195
  73.    End
  74.    Begin Label Label3 
  75.       BackColor       =   &H00C0C0C0&
  76.       Caption         =   "open invoices."
  77.       FontBold        =   -1  'True
  78.       FontItalic      =   -1  'True
  79.       FontName        =   "MS Sans Serif"
  80.       FontSize        =   8.25
  81.       FontStrikethru  =   0   'False
  82.       FontUnderline   =   0   'False
  83.       Height          =   255
  84.       Left            =   3090
  85.       TabIndex        =   5
  86.       Top             =   2160
  87.       Width           =   1695
  88.    End
  89.    Begin Label Label1 
  90.       BackColor       =   &H00C0C0C0&
  91.       Caption         =   "This customer has"
  92.       FontBold        =   -1  'True
  93.       FontItalic      =   -1  'True
  94.       FontName        =   "MS Sans Serif"
  95.       FontSize        =   8.25
  96.       FontStrikethru  =   0   'False
  97.       FontUnderline   =   0   'False
  98.       Height          =   255
  99.       Left            =   1080
  100.       TabIndex        =   4
  101.       Top             =   2160
  102.       Width           =   1695
  103.    End
  104.    Begin Label lblCustomerName 
  105.       BorderStyle     =   1  'Fixed Single
  106.       DataField       =   "CustomerName"
  107.       DataSource      =   "Data1"
  108.       FontBold        =   -1  'True
  109.       FontItalic      =   0   'False
  110.       FontName        =   "Courier"
  111.       FontSize        =   9.75
  112.       FontStrikethru  =   0   'False
  113.       FontUnderline   =   0   'False
  114.       Height          =   255
  115.       Left            =   2010
  116.       TabIndex        =   3
  117.       Top             =   480
  118.       Width           =   1425
  119.    End
  120.    Begin Label Label2 
  121.       BackColor       =   &H00C0C0C0&
  122.       Caption         =   "Invoice Date           Amount          Terms"
  123.       Height          =   255
  124.       Left            =   960
  125.       TabIndex        =   1
  126.       Top             =   840
  127.       Width           =   3615
  128.    End
  129.    Begin Menu mnuFile 
  130.       Caption         =   "&File"
  131.       Begin Menu mnuExit 
  132.          Caption         =   "E&xit"
  133.       End
  134.    End
  135.    Begin Menu mnuExplain 
  136.       Caption         =   "&Explain"
  137.    End
  138. Option Explicit
  139. 'Program FPDEMO1
  140. 'October 1993
  141. 'By: Sam Cohen
  142. 'Software Source
  143. '42808 Christy St., Ste. 222
  144. 'Fremont, CA  94538  USA
  145. 'Tel +1(510)623-7854   Fax +1(510)651-6039
  146. 'Most of the commentary in this program is in the single
  147. 'subroutine "LoadListBox."   (The only other code at all
  148. 'is in Form_Load, lblCustomerName_Change, mnuExplain, and
  149. 'mnuExit.)
  150. Sub Form_Load ()
  151.     Dim rc As Integer
  152.     MsgBox "This program expects to find the file FPDEMO1.MDB in the root directory of your C: drive.  Please wait while the VB3 MS-Access engine opens this file.", 64, "FieldPack Demo Program 1 -- Software Source"
  153.     rc = FP_Password("Sorry, you'll have to register to get a proper password.")
  154. End Sub
  155. Sub lblCustomerName_Change ()
  156.     'A change to this data-linked control means that
  157.     'we need to reload the list box, since the user has
  158.     'selected a new record.  Each record represents a
  159.     'different customer.  There are three fields in each
  160.     'record:  customer name (which is automatically dis-
  161.     'played in the caption of this data-linked label
  162.     'control); the number of "packed" invoices; and a
  163.     'SuperString (physically stored as a Memo field in
  164.     'the Access database file) containing the packed
  165.     'invoices.  We use a SuperString function to unpack
  166.     'the invoice information and display it in the list
  167.     'box, one invoice per line.
  168.     LoadListBox
  169. End Sub
  170. Sub LoadListBox ()
  171.     Dim SS_Format As String
  172.     Dim NumberOfInvoices As Integer
  173.     Dim InvoiceCount As String
  174.     Dim SuperString As String
  175.     Dim Invoice As String
  176.     Dim InvoiceDate As String
  177.     Dim Amount As String
  178.     Dim Terms As String
  179.     Dim ListBoxLine As String
  180.     Dim LoopCounter As Integer
  181.     Dim rc As Integer
  182.     lstInvoices.Clear       'Just to be neat, let's first clear out the list box.
  183.     SuperString = Data1.Recordset.Fields("Invoices").Value   'Reads the SuperString out of the Access database.
  184.     InvoiceCount = US_StripOut((txt_hidden_NumberOfInvoices.Text), " ")   'Note data-linked text box.
  185.     SS_Format = "A" + InvoiceCount + "$"
  186.         'The above line of code builds the "Format Description String" we need to supply with
  187.         'any call to a SuperString function (such as the SS_FetchItem call you see below).
  188.         'In this demo, we use a simple SuperString format consisting of only one "piece,"
  189.         'an array of variable length strings.  The number of array elements varies from
  190.         'instance to instance (i.e., from record to record).  Each array element (variable-
  191.         'length string) contains information about a single invoice.  So, if customer XYZ
  192.         'has 6 invoices outstanding, the SuperString for that record contains a 6-element
  193.         'array of variable-length strings, and that SuperString is described with the
  194.         'format string "A6$".
  195.     lblCountDisplay.Caption = InvoiceCount   'Big red digits.
  196.     NumberOfInvoices = Val(InvoiceCount)
  197.     For LoopCounter = 1 To NumberOfInvoices
  198.         rc = SS_FetchItem(SuperString, SS_Format, LoopCounter, "$", Invoice)
  199.             'The above function call extracts an "item" (in this case, a string containing
  200.             'information about a single invoice) from a SuperString.
  201.         If rc <> 0 Then MsgBox "SS error " + Str$(rc)
  202.         'Now, we're going to switch gears and demonstrate use of our Delimited Substring (DS_)
  203.         'capabilities (in a very minor way); the DS_GetField calls pick out variable-length
  204.         'substrings ("fields") delimited, in this case, by the "|" character:
  205.         InvoiceDate = DS_GetField(Invoice, "|", 1)
  206.         Amount = DS_GetField(Invoice, "|", 2)
  207.         Terms = DS_GetField(Invoice, "|", 3)
  208.         'Finally, just for completeness, the next line demonstrates use of some of our Utility
  209.         'String (US_) functions.  (We actually used one of these functions a few lines earlier,
  210.         'to remove blank characters from a string.)
  211.         ListBoxLine = US_LJustify(InvoiceDate, 11, " ") + " " + US_RJustify(Amount, 7, "$") + " " + US_RJustify(Terms, 8, " ")
  212.         
  213.         lstInvoices.AddItem ListBoxLine
  214.     Next LoopCounter
  215. End Sub
  216. Sub mnuExit_Click ()
  217.     End
  218. End Sub
  219. Sub mnuExplain_Click ()
  220.     Dim K As Integer
  221.     Dim Msg As String
  222.     Msg = "This is a very simple demo of how you can use SuperStrings to store a VARIABLE NUMBER of subrecords in a database record.  "
  223.     Msg = Msg + "(SuperStrings are one of the three capabilities in FieldPack.)  "
  224.     Msg = Msg + "In this case, we use a file of customer records, each of which contains a different number of invoice subrecords.  "
  225.     Msg = Msg + Chr$(10) + Chr$(10)
  226.     Msg = Msg + "We use a single MS-Access table of customer records.  Each record has three fields:  "
  227.     Msg = Msg + "customer name, number of invoices (N), and a Memo field.  The Memo field is a SuperString, "
  228.     Msg = Msg + "into which we're packed N invoice 'subrecords.'"
  229.     Msg = Msg + Chr$(10) + Chr$(10)
  230.     Msg = Msg + "Remember, this program is just an illustration of one of the simplest applications of SuperStrings.  "
  231.     Msg = Msg + "By all means, look at the source code; there's only one subroutine ('LoadListBox')."
  232.     MsgBox Msg, 64, "FieldPack Demo Program 1 -- Software Source"
  233. End Sub
  234.